<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<div id="div1">
			<p id="p1">这是一个段落。</p>
			<p id="p2">这是另外一个段落。</p>
		</div>
		<button type="button" onclick="deleteElement()">删除p1-方式1</button>
		<button type="button" onclick="deleteElement()">删除p1-方式2</button>
		<script>
			function deleteElement(){
				var div=document.getElementById("div1");
				var p1=document.getElementById("p1");
				//从父元素div中删除子元素p1
				div.removeChild(p1);
			}
			function deleteElement2(){
				var p1=document.getElementById("p1");
				//p1.parentNode：作用就是获取要删除元素p1的父元素div
				p1.parentNode.removeChild(p1);
			}
		</script>
	</body>
</html>
